<html>
<head>
  <title>13-统计数据的收集</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="YXBJ Windows/600646 (zh-CN, DDL); Windows/6.1.1 (Win64);"/>
  <meta name="content-class" content="yinxiang.markdown"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="769"/>
<h1>13-统计数据的收集</h1>

<div><span><div style="font-size: 14px; margin: 0; padding: 0; width: 100%;"><p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">前情回顾</strong></p>
<ul style="line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;">
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;">查看表的统计数据：SHOW TABLE STATUS LIKE 表名；</p>
</li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;">查看索引的统计数据：SHOW INDEX FROM 表名；</p>
</li>
</ul>
<h3 style="line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;">统计数据的存储方式</h3>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">InnoDB提供了两种存储统计数据的方式：</p>
<ul style="line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;">
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">永久性统计数据</strong><br/>
这种方式将统计数据存储在<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">磁盘</strong>上，也就是说服务器重启后这些统计数据还在。</p>
</li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">非永久性统计数据</strong><br/>
这种方式将统计数据存储在<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">内存</strong>中，当服务器关闭时这些这些统计数据就都被清除掉了，等到服务器重启之后，在某些适当的场景下才会重新收集这些统计数据。</p>
</li>
</ul>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">MySQL提供了系统变量来控制统计数据的存储方式：<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">innodb_stats_persistent</strong></p>
<ul style="line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;">
<li style="line-height: 160%; box-sizing: content-box; position: relative;">MySQL5.6.6之前，innodb_stats_persistent的值默认是OFF，也就是InnoDB的统计数据默认是存储到内存中的；</li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;">之后的版本中，innodb_stats_persistent的值默认是ON，也就是InnoDB的统计数据默认是存储到磁盘中的；</li>
</ul>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">不过InnoDB默认是<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">表为单位来收集和存储统计数据（以及该表的索引统计数据）的</strong>，可以在创建和修改表的时候通过指定STATS_PERSISTENT属性来指明该表的统计数据存储方式：</p>
<ul style="line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;">
<li style="line-height: 160%; box-sizing: content-box; position: relative;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">create table 表名（.. ）Engine=InnoDB，STATS_PERSISTENT=（ 1 | 0 ）；</strong></li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">alter table 表名（... ）Engine=InnoDB，STATS_PERSISTENT=（ 1 | 0 ）；</strong></li>
</ul>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">当<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">STATS_PERSISTENT=1</strong>时，表示该表的统计数据是<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">永久存储到磁盘</strong>上；<br/>
当<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">STATS_PERSISTENT=0</strong>时，表示该表的统计数据是<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">临时存储到内存</strong>中；<br/>
如果在创建表时未指定该属性，那么默认采用系统变量innodb_stats_persistent的值作为该属性的值。</p>
<h3 style="line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;">基于磁盘的永久性统计数据</h3>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">当把某个表以及该表索引的统计数据存放到磁盘上时，实际上是把这些统计数据存储到两个表里：<br/>
<img src="13-统计数据的收集_files/Image.png" type="image/png" data-filename="Image.png"/></p>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">可以看到，这两个表都位于mysql系统数据库下边，其中：</p>
<ul style="line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;">
<li style="line-height: 160%; box-sizing: content-box; position: relative;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">innodb_table_stats</strong>： 存储了关于表的统计数据，每一条记录对应着<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">一个表的统计数据</strong>；</li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">innodb_index_stats</strong>：存储了关于索引的统计数据，每一条记录对应着<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">一个索引的一个统计项的统计数据</strong>。</li>
</ul>
<h4 style="line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;">innodb_table_stats</h4>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><img src="13-统计数据的收集_files/Image [1].png" type="image/png" data-filename="Image.png"/></p>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">这个表的主键是(database_name,table_name)，也就是innodb_table_stats表的每条记录代表着一个表的统计信息。其中后三项统计数据都是估计值，是通过表空间、页面结构、记录结构等统计出来的。</p>
<h4 style="line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;">innodb_index_stats</h4>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><img src="13-统计数据的收集_files/Image [2].png" type="image/png" data-filename="Image.png"/></p>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">这个表的主键是(database_name,table_name,index_name,stat_name)，其中的<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">stat_name是指统计项的名称</strong>，也就是说innodb_index_stats表的每条记录代表着一个索引的一个统计项。</p>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">部分列：<br/>
<img src="13-统计数据的收集_files/Image [3].png" type="image/png" data-filename="Image.png"/><br/>
重点看以下几个列：</p>
<ul style="line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;">
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">stat_name</strong>：表示针对该索引的统计项<br/>
a. n_leaf_pages 表示该索引的叶子节点占用的页面数量<br/>
b. size：表示该索引共占用多少页面<br/>
c. n_diff_pfxNN：表示对应的索引列不重复的值<br/>
其实NN可以被替换为01、02、03... 这样的数字。比如对于idx_key_part来说：<br/>
$ n_diff_pfx01表示的是统计key_part1这单单一个列不重复的值有多少；<br/>
$ n_diff_pfx02表示的是统计key_part1、key_part2这两个列组合起来不重复的值有多少；<br/>
$ n_diff_pfx03表示的是统计key_part1、key_part2、key_part3这三个列组合起来不重复的值有多少；<br/>
$ n_diff_pfx04表示的是统计key_part1、key_part2、key_part3、id这四个列组合起来不重复的值有多少；</p>
</li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">stat_value</strong>：表示该统计项的值</p>
</li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">sample_size</strong>：在计算某些索引列中包含多少不重复值时，需要对一些叶子节点页面进行采样，sample_size就表示采样的页面数量。<br/>
对于有多个列的联合索引来说，采样的页面数量是：innodb_stats_persistent_sample_pages × 索引列的个数。当需要采样的页面数量大于该索引的叶子节点数量的话，就直接采用全表扫描来统计索引列的不重复值数量了。所以大家可以在查询结果中看到不同索引对应的size列的值可能是不同的。</p>
</li>
</ul>
<h4 style="line-height: 160%; box-sizing: content-box; font-size: 20px; color: #333;">定期更新统计数据</h4>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">MySQL提供了两种更新统计数据的方式：</p>
<ul style="line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;">
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;">开启innodb_stats_auto_recalc<br/>
系统变量innodb_stats_auto_recalc决定着服务器是否自动重新计算统计数据，它的默认值是ON，也就是该功能默认是开启的。每个表都维护了一个变量，该变量记录着对该表进行增删改的记录条数，如果发生变动的记录数量超过了表大小的10%，并且自动重新计算统计数据的功能是打开的，那么服务器会重新进行一次统计数据的计算，并且更新innodb_table_stats和innodb_index_stats表。不过自动重新计算统计数据的过程是异步发生的，也就是即使表中变动的记录数超过了10%，自动重新计算统计数据也不会立即发生，可能会延迟几秒才会进行计算。<br/>
再一次强调，InnoDB默认是以表为单位来收集和存储统计数据的，我们也可以单独为某个表设置是否自动重新计算统计数的属性，设置方式就是在创建或修改表的时候通过指定<strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">STATS_AUTO_RECALC</strong>属性来指明该表的统计数据存储方式：<br/>
<img src="13-统计数据的收集_files/Image [4].png" type="image/png" data-filename="Image.png"/><br/>
当STATS_AUTO_RECALC=1时，表明我们想让该表自动重新计算统计数据，当STATS_PERSISTENT=0时，表明不想让该表自动重新计算统计数据。如果我们在创建表时未指定STATS_AUTO_RECALC属性，那默认采用系统变量innodb_stats_auto_recalc的值作为该属性的值。</p>
</li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;">手动调用ANALYZE TABLE语句来更新统计信息<br/>
如果innodb_stats_auto_recalc系统变量的值为OFF的话，我们也可以手动调用ANALYZE TABLE语句来重新计算统计数据：<img src="13-统计数据的收集_files/Image [5].png" type="image/png" data-filename="Image.png"/><br/>
需要注意的是，ANALYZE TABLE语句会立即重新计算统计数据，也就是这个过程是同步的，在表中索引多或者采样页面特别多时这个过程可能会特别慢，请不要没事儿就运行一下ANALYZE TABLE语句，最好在业务不是很繁忙的时候再运行。</p>
</li>
</ul>
<h3 style="line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;">基于内存的非永久性统计数据</h3>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><img src="13-统计数据的收集_files/Image [6].png" type="image/png" data-filename="Image.png"/></p>
<h3 style="line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 27px; color: #333;">innodb_stats_method的使用</h3>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">索引列不重复的值的数量这个统计数据对于MySQL查询优化器十分重要，因为通过它可以计算出在索引列中平均一个值重复多少行，它的应用场景主要有两个：</p>
<ul style="line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;">
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;">单表查询中单点区间太多，比方说这样：<br/>
SELECT * FROM tbl_name WHERE key IN ('xx1', 'xx2', ..., 'xxn')；<br/>
当IN里的参数数量过多时，采用index dive的方式直接访问B+树索引去统计每个单点区间对应的记录的数量就太耗费性能了，所以直接依赖统计数据中的平均一个值重复多少行来计算单点区间对应的记录数量。</p>
</li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;">连接查询时，如果有涉及两个表的等值匹配连接条件，该连接条件对应的被驱动表中的列又拥有索引时，则可以使用ref访问方法来对被驱动表进行查询：<br/>
SELECT * FROM t1 JOIN t2 ON t1.column = t2.key WHERE ...；<br/>
在真正执行对t2表的查询前，t1.comumn的值是不确定的，所以我们也不能通过index dive的方式直接访问B+树索引去统计每个单点区间对应的记录的数量，所以也只能依赖统计数据中的平均一个值重复多少行来计算单点区间对应的记录数量。</p>
</li>
</ul>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">在统计索引列不重复的值的数量时，有一个比较烦的问题就是索引列中出现NULL值怎么办，比方说某个索引列的内容是这样：<br/>
<img src="13-统计数据的收集_files/Image [7].png" type="image/png" data-filename="Image.png"/></p>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">设计MySQL的大叔蛮贴心的，他们提供了一个名为innodb_stats_method的系统变量，相当于在计算某个索引列不重复值的数量时如何对待NULL值这个锅甩给了用户，这个系统变量有三个候选值：</p>
<ul style="line-height: 160%; box-sizing: content-box; display: block; list-style-type: disc; padding-left: 30px; margin: 6px 0 10px; color: #333;">
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">nulls_equal</strong>：认为所有NULL值都是相等的。这个值也是innodb_stats_method的默认值。<br/>
如果某个索引列中NULL值特别多的话，这种统计方式会让优化器认为某个列中平均一个值重复次数特别多，成本分析时得出的成本值比较大。</p>
</li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">nulls_unequal</strong>：认为所有NULL值都是不相等的。如果某个索引列中NULL值特别多的话，这种统计方式会让优化器认为某个列中平均一个值重复次数特别少，所以倾向于使用索引进行访问。</p>
</li>
<li style="line-height: 160%; box-sizing: content-box; position: relative;">
<p style="line-height: 160%; box-sizing: content-box; color: #333; margin: 0;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">nulls_ignored</strong>：直接把NULL值忽略掉。</p>
</li>
</ul>
</div><center style="display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden">**%E5%89%8D%E6%83%85%E5%9B%9E%E9%A1%BE**%0A%0A*%20%E6%9F%A5%E7%9C%8B%E8%A1%A8%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%EF%BC%9ASHOW%20TABLE%20STATUS%20LIKE%20%E8%A1%A8%E5%90%8D%EF%BC%9B%0A%0A*%20%E6%9F%A5%E7%9C%8B%E7%B4%A2%E5%BC%95%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%EF%BC%9ASHOW%20INDEX%20FROM%20%E8%A1%A8%E5%90%8D%EF%BC%9B%0A%0A%23%23%23%20%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E7%9A%84%E5%AD%98%E5%82%A8%E6%96%B9%E5%BC%8F%0AInnoDB%E6%8F%90%E4%BE%9B%E4%BA%86%E4%B8%A4%E7%A7%8D%E5%AD%98%E5%82%A8%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E7%9A%84%E6%96%B9%E5%BC%8F%EF%BC%9A%0A%0A*%20**%E6%B0%B8%E4%B9%85%E6%80%A7%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE**%0A%E8%BF%99%E7%A7%8D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%E9%87%8F%E6%9D%A5%E6%8E%A7%E5%88%B6%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E7%9A%84%E5%AD%98%E5%82%A8%E6%96%B9%E5%BC%8F%EF%BC%9A**innodb_stats_persistent**%0A%0A*%20MySQL5.6.6%E4%B9%8B%E5%89%8D%EF%BC%8Cinnodb_stats_persistent%E7%9A%84%E5%80%BC%E9%BB%98%E8%AE%A4%E6%98%AFOFF%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AFInnoDB%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E9%BB%98%E8%AE%A4%E6%98%AF%E5%AD%98%E5%82%A8%E5%88%B0%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%EF%BC%9B%0A*%20%E4%B9%8B%E5%90%8E%E7%9A%84%E7%89%88%E6%9C%AC%E4%B8%AD%EF%BC%8Cinnodb_stats_persistent%E7%9A%84%E5%80%BC%E9%BB%98%E8%AE%A4%E6%98%AFON%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AFInnoDB%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E9%BB%98%E8%AE%A4%E6%98%AF%E5%AD%98%E5%82%A8%E5%88%B0%E7%A3%81%E7%9B%98%E4%B8%AD%E7%9A%84%EF%BC%9B%0A%0A%E4%B8%8D%E8%BF%87InnoDB%E9%BB%98%E8%AE%A4%E6%98%AF**%E8%A1%A8%E4%B8%BA%E5%8D%95%E4%BD%8D%E6%9D%A5%E6%94%B6%E9%9B%86%E5%92%8C%E5%AD%98%E5%82%A8%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%EF%BC%88%E4%BB%A5%E5%8F%8A%E8%AF%A5%E8%A1%A8%E7%9A%84%E7%B4%A2%E5%BC%95%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%EF%BC%89%E7%9A%84**%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%9C%A8%E5%88%9B%E5%BB%BA%E5%92%8C%E4%BF%AE%E6%94%B9%E8%A1%A8%E7%9A%84%E6%97%B6%E5%80%99%E9%80%9A%E8%BF%87%E6%8C%87%E5%AE%9ASTATS_PERSISTENT%E5%B1%9E%E6%80%A7%E6%9D%A5%E6%8C%87%E6%98%8E%E8%AF%A5%E8%A1%A8%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E5%AD%98%E5%82%A8%E6%96%B9%E5%BC%8F%EF%BC%9A%0A%0A*%20**create%20table%20%E8%A1%A8%E5%90%8D%EF%BC%88..%20%EF%BC%89Engine%3DInnoDB%EF%BC%8CSTATS_PERSISTENT%3D%EF%BC%88%201%20%7C%200%20%EF%BC%89%EF%BC%9B**%0A*%20**alter%20table%20%E8%A1%A8%E5%90%8D%EF%BC%88...%20%EF%BC%89Engine%3DInnoDB%EF%BC%8CSTATS_PERSISTENT%3D%EF%BC%88%201%20%7C%200%20%EF%BC%89%EF%BC%9B**%0A%0A%E5%BD%93**STATS_PERSISTENT%3D1**%E6%97%B6%EF%BC%8C%E8%A1%A8%E7%A4%BA%E8%AF%A5%E8%A1%A8%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E6%98%AF**%E6%B0%B8%E4%B9%85%E5%AD%98%E5%82%A8%E5%88%B0%E7%A3%81%E7%9B%98**%E4%B8%8A%EF%BC%9B%0A%E5%BD%93**STATS_PERSISTENT%3D0**%E6%97%B6%EF%BC%8C%E8%A1%A8%E7%A4%BA%E8%AF%A5%E8%A1%A8%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E6%98%AF**%E4%B8%B4%E6%97%B6%E5%AD%98%E5%82%A8%E5%88%B0%E5%86%85%E5%AD%98**%E4%B8%AD%EF%BC%9B%0A%E5%A6%82%E6%9E%9C%E5%9C%A8%E5%88%9B%E5%BB%BA%E8%A1%A8%E6%97%B6%E6%9C%AA%E6%8C%87%E5%AE%9A%E8%AF%A5%E5%B1%9E%E6%80%A7%EF%BC%8C%E9%82%A3%E4%B9%88%E9%BB%98%E8%AE%A4%E9%87%87%E7%94%A8%E7%B3%BB%E7%BB%9F%E5%8F%98%E9%87%8Finnodb_stats_persistent%E7%9A%84%E5%80%BC%E4%BD%9C%E4%B8%BA%E8%AF%A5%E5%B1%9E%E6%80%A7%E7%9A%84%E5%80%BC%E3%80%82%0A%0A%23%23%23%20%E5%9F%BA%E4%BA%8E%E7%A3%81%E7%9B%98%E7%9A%84%E6%B0%B8%E4%B9%85%E6%80%A7%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%0A%0A%E5%BD%93%E6%8A%8A%E6%9F%90%E4%B8%AA%E8%A1%A8%E4%BB%A5%E5%8F%8A%E8%AF%A5%E8%A1%A8%E7%B4%A2%E5%BC%95%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E5%AD%98%E6%94%BE%E5%88%B0%E7%A3%81%E7%9B%98%E4%B8%8A%E6%97%B6%EF%BC%8C%E5%AE%9E%E9%99%85%E4%B8%8A%E6%98%AF%E6%8A%8A%E8%BF%99%E4%BA%9B%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E5%AD%98%E5%82%A8%E5%88%B0%E4%B8%A4%E4%B8%AA%E8%A1%A8%E9%87%8C%EF%BC%9A%0A!%5B06442cb375356ebecb82318462e41eec.png%5D(en-resource%3A%2F%2Fdatabase%2F794%3A0)%0A%0A%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%88%B0%EF%BC%8C%E8%BF%99%E4%B8%A4%E4%B8%AA%E8%A1%A8%E9%83%BD%E4%BD%8D%E4%BA%8Emysql%E7%B3%BB%E7%BB%9F%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%8B%E8%BE%B9%EF%BC%8C%E5%85%B6%E4%B8%AD%EF%BC%9A%0A%0A*%20**innodb_table_stats**%EF%BC%9A%20%E5%AD%98%E5%82%A8%E4%BA%86%E5%85%B3%E4%BA%8E%E8%A1%A8%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%EF%BC%8C%E6%AF%8F%E4%B8%80%E6%9D%A1%E8%AE%B0%E5%BD%95%E5%AF%B9%E5%BA%94%E7%9D%80**%E4%B8%80%E4%B8%AA%E8%A1%A8%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE**%EF%BC%9B%0A*%20**innodb_index_stats**%EF%BC%9A%E5%AD%98%E5%82%A8%E4%BA%86%E5%85%B3%E4%BA%8E%E7%B4%A2%E5%BC%95%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%EF%BC%8C%E6%AF%8F%E4%B8%80%E6%9D%A1%E8%AE%B0%E5%BD%95%E5%AF%B9%E5%BA%94%E7%9D%80**%E4%B8%80%E4%B8%AA%E7%B4%A2%E5%BC%95%E7%9A%84%E4%B8%80%E4%B8%AA%E7%BB%9F%E8%AE%A1%E9%A1%B9%E7%9A%84%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE**%E3%80%82%0A%0A%23%23%23%23%20innodb_table_stats%0A!%5Bb75cc55f467b311a2e2b4d42621b6142.png%5D(en-resource%3A%2F%2Fdatabase%2F796%3A0)%0A%0A%E8%BF%99%E4%B8%AA%E8%A1%A8%E7%9A%84%E4%B8%BB%E9%94%AE%E6%98%AF(database_name%2Ctable_name)%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AFinnodb_table_stats%E8%A1%A8%E7%9A%84%E6%AF%8F%E6%9D%A1%E8%AE%B0%E5%BD%95%E4%BB%A3%E8%A1%A8%E7%9D%80%E4%B8%80%E4%B8%AA%E8%A1%A8%E7%9A%84%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%E3%80%82%E5%85%B6%E4%B8%AD%E5%90%8E%E4%B8%89%E9%A1%B9%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E9%83%BD%E6%98%AF%E4%BC%B0%E8%AE%A1%E5%80%BC%EF%BC%8C%E6%98%AF%E9%80%9A%E8%BF%87%E8%A1%A8%E7%A9%BA%E9%97%B4%E3%80%81%E9%A1%B5%E9%9D%A2%E7%BB%93%E6%9E%84%E3%80%81%E8%AE%B0%E5%BD%95%E7%BB%93%E6%9E%84%E7%AD%89%E7%BB%9F%E8%AE%A1%E5%87%BA%E6%9D%A5%E7%9A%84%E3%80%82%0A%0A%23%23%23%23%20innodb_index_stats%0A!%5B55594447007fd6f19799381892dab8b2.png%5D(en-resource%3A%2F%2Fdatabase%2F798%3A0)%0A%0A%E8%BF%99%E4%B8%AA%E8%A1%A8%E7%9A%84%E4%B8%BB%E9%94%AE%E6%98%AF(database_name%2Ctable_name%2Cindex_name%2Cstat_name)%EF%BC%8C%E5%85%B6%E4%B8%AD%E7%9A%84**stat_name%E6%98%AF%E6%8C%87%E7%BB%9F%E8%AE%A1%E9%A1%B9%E7%9A%84%E5%90%8D%E7%A7%B0**%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%AF%B4innodb_index_stats%E8%A1%A8%E7%9A%84%E6%AF%8F%E6%9D%A1%E8%AE%B0%E5%BD%95%E4%BB%A3%E8%A1%A8%E7%9D%80%E4%B8%80%E4%B8%AA%E7%B4%A2%E5%BC%95%E7%9A%84%E4%B8%80%E4%B8%AA%E7%BB%9F%E8%AE%A1%E9%A1%B9%E3%80%82%0A%0A%E9%83%A8%E5%88%86%E5%88%97%EF%BC%9A%0A!%5B228f5db52400999ffd8d117a9141e081.png%5D(en-resource%3A%2F%2Fdatabase%2F800%3A0)%0A%E9%87%8D%E7%82%B9%E7%9C%8B%E4%BB%A5%E4%B8%8B%E5%87%A0%E4%B8%AA%E5%88%97%EF%BC%9A%0A%0A*%20**stat_name**%EF%BC%9A%E8%A1%A8%E7%A4%BA%E9%92%88%E5%AF%B9%E8%AF%A5%E7%B4%A2%E5%BC%95%E7%9A%84%E7%BB%9F%E8%AE%A1%E9%A1%B9%0Aa.%20n_leaf_pages%20%E8%A1%A8%E7%A4%BA%E8%AF%A5%E7%B4%A2%E5%BC%95%E7%9A%84%E5%8F%B6%E5%AD%90%E8%8A%82%E7%82%B9%E5%8D%A0%E7%94%A8%E7%9A%84%E9%A1%B5%E9%9D%A2%E6%95%B0%E9%87%8F%0Ab.%20size%EF%BC%9A%E8%A1%A8%E7%A4%BA%E8%AF%A5%E7%B4%A2%E5%BC%95%E5%85%B1%E5%8D%A0%E7%94%A8%E5%A4%9A%E5%B0%91%E9%A1%B5%E9%9D%A2%0Ac.%20n_diff_pfxNN%EF%BC%9A%E8%A1%A8%E7%A4%BA%E5%AF%B9%E5%BA%94%E7%9A%84%E7%B4%A2%E5%BC%95%E5%88%97%E4%B8%8D%E9%87%8D%E5%A4%8D%E7%9A%84%E5%80%BC%0A%E5%85%B6%E5%AE%9ENN%E5%8F%AF%E4%BB%A5%E8%A2%AB%E6%9B%BF%E6%8D%A2%E4%B8%BA01%E3%80%8102%E3%80%8103...%20%E8%BF%99%E6%A0%B7%E7%9A%84%E6%95%B0%E5%AD%97%E3%80%82%E6%AF%94%E5%A6%82%E5%AF%B9%E4%BA%8Eidx_key_part%E6%9D%A5%E8%AF%B4%EF%BC%9A%0A%24%20n_diff_pfx01%E8%A1%A8%E7%A4%BA%E7%9A%84%E6%98%AF%E7%BB%9F%E8%AE%A1key_part1%E8%BF%99%E5%8D%95%E5%8D%95%E4%B8%80%E4%B8%AA%E5%88%97%E4%B8%8D%E9%87%8D%E5%A4%8D%E7%9A%84%E5%80%BC%E6%9C%89%E5%A4%9A%E5%B0%91%EF%BC%9B%0A%24%20n_diff_pfx02%E8%A1%A8%E7%A4%BA%E7%9A%84%E6%98%AF%E7%BB%9F%E8%AE%A1key_part1%E3%80%81key_part2%E8%BF%99%E4%B8%A4%E4%B8%AA%E5%88%97%E7%BB%84%E5%90%88%E8%B5%B7%E6%9D%A5%E4%B8%8D%E9%87%8D%E5%A4%8D%E7%9A%84%E5%80%BC%E6%9C%89%E5%A4%9A%E5%B0%91%EF%BC%9B%0A%24%20n_diff_pfx03%E8%A1%A8%E7%A4%BA%E7%9A%84%E6%98%AF%E7%BB%9F%E8%AE%A1key_part1%E3%80%81key_part2%E3%80%81key_part3%E8%BF%99%E4%B8%89%E4%B8%AA%E5%88%97%E7%BB%84%E5%90%88%E8%B5%B7%E6%9D%A5%E4%B8%8D%E9%87%8D%E5%A4%8D%E7%9A%84%E5%80%BC%E6%9C%89%E5%A4%9A%E5%B0%91%EF%BC%9B%0A%24%20n_diff_pfx04%E8%A1%A8%E7%A4%BA%E7%9A%84%E6%98%AF%E7%BB%9F%E8%AE%A1key_part1%E3%80%81key_part2%E3%80%81key_part3%E3%80%81id%E8%BF%99%E5%9B%9B%E4%B8%AA%E5%88%97%E7%BB%84%E5%90%88%E8%B5%B7%E6%9D%A5%E4%B8%8D%E9%87%8D%E5%A4%8D%E7%9A%84%E5%80%BC%E6%9C%89%E5%A4%9A%E5%B0%91%EF%BC%9B%0A%0A%0A*%20**stat_value**%EF%BC%9A%E8%A1%A8%E7%A4%BA%E8%AF%A5%E7%BB%9F%E8%AE%A1%E9%A1%B9%E7%9A%84%E5%80%BC%0A*%20**sample_size**%EF%BC%9A%E5%9C%A8%E8%AE%A1%E7%AE%97%E6%9F%90%E4%BA%9B%E7%B4%A2%E5%BC%95%E5%88%97%E4%B8%AD%E5%8C%85%E5%90%AB%E5%A4%9A%E5%B0%91%E4%B8%8D%E9%87%8D%E5%A4%8D%E5%80%BC%E6%97%B6%EF%BC%8C%E9%9C%80%E8%A6%81%E5%AF%B9%E4%B8%80%E4%BA%9B%E5%8F%B6%E5%AD%90%E8%8A%82%E7%82%B9%E9%A1%B5%E9%9D%A2%E8%BF%9B%E8%A1%8C%E9%87%87%E6%A0%B7%EF%BC%8Csample_size%E5%B0%B1%E8%A1%A8%E7%A4%BA%E9%87%87%E6%A0%B7%E7%9A%84%E9%A1%B5%E9%9D%A2%E6%95%B0%E9%87%8F%E3%80%82%0A%E5%AF%B9%E4%BA%8E%E6%9C%89%E5%A4%9A%E4%B8%AA%E5%88%97%E7%9A%84%E8%81%94%E5%90%88%E7%B4%A2%E5%BC%95%E6%9D%A5%E8%AF%B4%EF%BC%8C%E9%87%87%E6%A0%B7%E7%9A%84%E9%A1%B5%E9%9D%A2%E6%95%B0%E9%87%8F%E6%98%AF%EF%BC%9Ainnodb_stats_persistent_sample_pages%20%C3%97%20%E7%B4%A2%E5%BC%95%E5%88%97%E7%9A%84%E4%B8%AA%E6%95%B0%E3%80%82%E5%BD%93%E9%9C%80%E8%A6%81%E9%87%87%E6%A0%B7%E7%9A%84%E9%A1%B5%E9%9D%A2%E6%95%B0%E9%87%8F%E5%A4%A7%E4%BA%8E%E8%AF%A5%E7%B4%A2%E5%BC%95%E7%9A%84%E5%8F%B6%E5%AD%90%E8%8A%82%E7%82%B9%E6%95%B0%E9%87%8F%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%B0%B1%E7%9B%B4%E6%8E%A5%E9%87%87%E7%94%A8%E5%85%A8%E8%A1%A8%E6%89%AB%E6%8F%8F%E6%9D%A5%E7%BB%9F%E8%AE%A1%E7%B4%A2%E5%BC%95%E5%88%97%E7%9A%84%E4%B8%8D%E9%87%8D%E5%A4%8D%E5%80%BC%E6%95%B0%E9%87%8F%E4%BA%86%E3%80%82%E6%89%80%E4%BB%A5%E5%A4%A7%E5%AE%B6%E5%8F%AF%E4%BB%A5%E5%9C%A8%E6%9F%A5%E8%AF%A2%E7%BB%93%E6%9E%9C%E4%B8%AD%E7%9C%8B%E5%88%B0%E4%B8%8D%E5%90%8C%E7%B4%A2%E5%BC%95%E5%AF%B9%E5%BA%94%E7%9A%84size%E5%88%97%E7%9A%84%E5%80%BC%E5%8F%AF%E8%83%BD%E6%98%AF%E4%B8%8D%E5%90%8C%E7%9A%84%E3%80%82%0A%0A%23%23%23%23%20%E5%AE%9A%E6%9C%9F%E6%9B%B4%E6%96%B0%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%0A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BC%8C%E5%BD%93STATS_PERSISTENT%3D0%E6%97%B6%EF%BC%8C%E8%A1%A8%E6%98%8E%E4%B8%8D%E6%83%B3%E8%AE%A9%E8%AF%A5%E8%A1%A8%E8%87%AA%E5%8A%A8%E9%87%8D%E6%96%B0%E8%AE%A1%E7%AE%97%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%E3%80%82%E5%A6%82%E6%9E%9C%E6%88%91%E4%BB%AC%E5%9C%A8%E5%88%9B%E5%BB%BA%E8%A1%A8%E6%97%B6%E6%9C%AA%E6%8C%87%E5%AE%9ASTATS_AUTO_RECALC%E5%B1%9E%E6%80%A7%EF%BC%8C%E9%82%A3%E9%BB%98%E8%AE%A4%E9%87%87%E7%94%A8%E7%B3%BB%E7%BB%9F%E5%8F%98%E9%87%8Finnodb_stats_auto_recalc%E7%9A%84%E5%80%BC%E4%BD%9C%E4%B8%BA%E8%AF%A5%E5%B1%9E%E6%80%A7%E7%9A%84%E5%80%BC%E3%80%82%0A%0A*%20%E6%89%8B%E5%8A%A8%E8%B0%83%E7%94%A8ANALYZE%20TABLE%E8%AF%AD%E5%8F%A5%E6%9D%A5%E6%9B%B4%E6%96%B0%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%0A%E5%A6%82%E6%9E%9Cinnodb_stats_auto_recalc%E7%B3%BB%E7%BB%9F%E5%8F%98%E9%87%8F%E7%9A%84%E5%80%BC%E4%B8%BAOFF%E7%9A%84%E8%AF%9D%EF%BC%8C%E6%88%91%E4%BB%AC%E4%B9%9F%E5%8F%AF%E4%BB%A5%E6%89%8B%E5%8A%A8%E8%B0%83%E7%94%A8ANALYZE%20TABLE%E8%AF%AD%E5%8F%A5%E6%9D%A5%E9%87%8D%E6%96%B0%E8%AE%A1%E7%AE%97%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%EF%BC%9A!%5B73d3003430eef5da501006c32d55f27f.png%5D(en-resource%3A%2F%2Fdatabase%2F804%3A0)%0A%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%E7%9A%84%E6%98%AF%EF%BC%8CANALYZE%20TABLE%E8%AF%AD%E5%8F%A5%E4%BC%9A%E7%AB%8B%E5%8D%B3%E9%87%8D%E6%96%B0%E8%AE%A1%E7%AE%97%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E8%BF%99%E4%B8%AA%E8%BF%87%E7%A8%8B%E6%98%AF%E5%90%8C%E6%AD%A5%E7%9A%84%EF%BC%8C%E5%9C%A8%E8%A1%A8%E4%B8%AD%E7%B4%A2%E5%BC%95%E5%A4%9A%E6%88%96%E8%80%85%E9%87%87%E6%A0%B7%E9%A1%B5%E9%9D%A2%E7%89%B9%E5%88%AB%E5%A4%9A%E6%97%B6%E8%BF%99%E4%B8%AA%E8%BF%87%E7%A8%8B%E5%8F%AF%E8%83%BD%E4%BC%9A%E7%89%B9%E5%88%AB%E6%85%A2%EF%BC%8C%E8%AF%B7%E4%B8%8D%E8%A6%81%E6%B2%A1%E4%BA%8B%E5%84%BF%E5%B0%B1%E8%BF%90%E8%A1%8C%E4%B8%80%E4%B8%8BANALYZE%20TABLE%E8%AF%AD%E5%8F%A5%EF%BC%8C%E6%9C%80%E5%A5%BD%E5%9C%A8%E4%B8%9A%E5%8A%A1%E4%B8%8D%E6%98%AF%E5%BE%88%E7%B9%81%E5%BF%99%E7%9A%84%E6%97%B6%E5%80%99%E5%86%8D%E8%BF%90%E8%A1%8C%E3%80%82%0A%0A%23%23%23%20%E5%9F%BA%E4%BA%8E%E5%86%85%E5%AD%98%E7%9A%84%E9%9D%9E%E6%B0%B8%E4%B9%85%E6%80%A7%E7%BB%9F%E8%AE%A1%E6%95%B0%E6%8D%AE%0A!%5B706a3ebc1eb450be5f84013ff4a5e302.png%5D(en-resource%3A%2F%2Fdatabase%2F808%3A0)%0A%0A%23%23%23%20innodb_stats_method%E7%9A%84%E4%BD%BF%E7%94%A8%0A%0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97%E4%B8%8D%E9%87%8D%E5%A4%8D%E7%9A%84%E5%80%BC%E7%9A%84%E6%95%B0%E9%87%8F%E6%97%B6%EF%BC%8C%E6%9C%89%E4%B8%80%E4%B8%AA%E6%AF%94%E8%BE%83%E7%83%A6%E7%9A%84%E9%97%AE%E9%A2%98%E5%B0%B1%E6%98%AF%E7%B4%A2%E5%BC%95%E5%88%97%E4%B8%AD%E5%87%BA%E7%8E%B0NULL%E5%80%BC%E6%80%8E%E4%B9%88%E5%8A%9E%EF%BC%8C%E6%AF%94%E6%96%B9%E8%AF%B4%E6%9F%90%E4%B8%AA%E7%B4%A2%E5%BC%95%E5%88%97%E7%9A%84%E5%86%85%E5%AE%B9%E6%98%AF%E8%BF%99%E6%A0%B7%EF%BC%9A%0A!%5Bb8a599354cc46076f27870e284a0c6a7.png%5D(en-resource%3A%2F%2Fdatabase%2F810%3A0)%0A%0A%E8%AE%BE%E8%AE%A1MySQL%E7%9A%84%E5%A4%A7%E5%8F%94%E8%9B%AE%E8%B4%B4%E5%BF%83%E7%9A%84%EF%BC%8C%E4%BB%96%E4%BB%AC%E6%8F%90%E4%BE%9B%E4%BA%86%E4%B8%80%E4%B8%AA%E5%90%8D%E4%B8%BAinnodb_stats_method%E7%9A%84%E7%B3%BB%E7%BB%9F%E5%8F%98%E9%87%8F%EF%BC%8C%E7%9B%B8%E5%BD%93%E4%BA%8E%E5%9C%A8%E8%AE%A1%E7%AE%97%E6%9F%90%E4%B8%AA%E7%B4%A2%E5%BC%95%E5%88%97%E4%B8%8D%E9%87%8D%E5%A4%8D%E5%80%BC%E7%9A%84%E6%95%B0%E9%87%8F%E6%97%B6%E5%A6%82%E4%BD%95%E5%AF%B9%E5%BE%85NULL%E5%80%BC%E8%BF%99%E4%B8%AA%E9%94%85%E7%94%A9%E7%BB%99%E4%BA%86%E7%94%A8%E6%88%B7%EF%BC%8C%E8%BF%99%E4%B8%AA%E7%B3%BB%E7%BB%9F%E5%8F%98%E9%87%8F%E6%9C%89%E4%B8%89%E4%B8%AA%E5%80%99%E9%80%89%E5%80%BC%EF%BC%9A%0A%0A*%20**nulls_equal**%EF%BC%9A%E8%AE%A4%E4%B8%BA%E6%89%80%E6%9C%89NULL%E5%80%BC%E9%83%BD%E6%98%AF%E7%9B%B8%E7%AD%89%E7%9A%84%E3%80%82%E8%BF%99%E4%B8%AA%E5%80%BC%E4%B9%9F%E6%98%AFinnodb_stats_method%E7%9A%84%E9%BB%98%E8%AE%A4%E5%80%BC%E3%80%82%0A%E5%A6%82%E6%9E%9C%E6%9F%90%E4%B8%AA%E7%B4%A2%E5%BC%95%E5%88%97%E4%B8%ADNULL%E5%80%BC%E7%89%B9%E5%88%AB%E5%A4%9A%E7%9A%84%E8%AF%9D%EF%BC%8C%E8%BF%99%E7%A7%8D%E7%BB%9F%E8%AE%A1%E6%96%B9%E5%BC%8F%E4%BC%9A%E8%AE%A9%E4%BC%98%E5%8C%96%E5%99%A8%E8%AE%A4%E4%B8%BA%E6%9F%90%E4%B8%AA%E5%88%97%E4%B8%AD%E5%B9%B3%E5%9D%87%E4%B8%80%E4%B8%AA%E5%80%BC%E9%87%8D%E5%A4%8D%E6%AC%A1%E6%95%B0%E7%89%B9%E5%88%AB%E5%A4%9A%EF%BC%8C%E6%88%90%E6%9C%AC%E5%88%86%E6%9E%90%E6%97%B6%E5%BE%97%E5%87%BA%E7%9A%84%E6%88%90%E6%9C%AC%E5%80%BC%E6%AF%94%E8%BE%83%E5%A4%A7%E3%80%82%0A%0A*%20**nulls_unequal**%EF%BC%9A%E8%AE%A4%E4%B8%BA%E6%89%80%E6%9C%89NULL%E5%80%BC%E9%83%BD%E6%98%AF%E4%B8%8D%E7%9B%B8%E7%AD%89%E7%9A%84%E3%80%82%E5%A6%82%E6%9E%9C%E6%9F%90%E4%B8%AA%E7%B4%A2%E5%BC%95%E5%88%97%E4%B8%ADNULL%E5%80%BC%E7%89%B9%E5%88%AB%E5%A4%9A%E7%9A%84%E8%AF%9D%EF%BC%8C%E8%BF%99%E7%A7%8D%E7%BB%9F%E8%AE%A1%E6%96%B9%E5%BC%8F%E4%BC%9A%E8%AE%A9%E4%BC%98%E5%8C%96%E5%99%A8%E8%AE%A4%E4%B8%BA%E6%9F%90%E4%B8%AA%E5%88%97%E4%B8%AD%E5%B9%B3%E5%9D%87%E4%B8%80%E4%B8%AA%E5%80%BC%E9%87%8D%E5%A4%8D%E6%AC%A1%E6%95%B0%E7%89%B9%E5%88%AB%E5%B0%91%EF%BC%8C%E6%89%80%E4%BB%A5%E5%80%BE%E5%90%91%E4%BA%8E%E4%BD%BF%E7%94%A8%E7%B4%A2%E5%BC%95%E8%BF%9B%E8%A1%8C%E8%AE%BF%E9%97%AE%E3%80%82%0A%0A*%20**nulls_ignored**%EF%BC%9A%E7%9B%B4%E6%8E%A5%E6%8A%8ANULL%E5%80%BC%E5%BF%BD%E7%95%A5%E6%8E%89%E3%80%82%0A</center></span>
</div></body></html> 